# ANES_1970_supplement.R

# Part of the replication archive for 
#
#   Bullock, John G. 2020. "Education and Attitudes toward Redistribution in
#   the United States." British Journal of Political Science 50.

#
# The 1970 ANES contains a "Negro supplement": more than 100 African-American
# respondents. Information from these respondents wasn't included in the 
# cumulative ANES. But these subjects may be meaningful; in particular, their 
# answers to the health-care question may be relevant.


library(Bullock, lib.loc = c(.libPaths(), 'packageLibrary'))  # for %IN%
library(car)      # for Recode()
library(dplyr)    # for %>%, left_join()
library(haven)    # for read_dta
library(stringr)  # for str_pad()
source('functions/mergeStateControlVars.R')
source('functions/NES_StateRecode.R')

ANES_1970 <- tempfile(fileext = '.zip')  
download.file(
  url      = 'https://electionstudies.org/wp-content/uploads/2018/06/anes1970dta.zip', 
  destfile = ANES_1970)
ANES1970 <- unz(ANES_1970, 'NES1970.dta') %>% 
  read_dta() %>%
  zap_labels()

ANES1970$ID.unique <- str_pad(ANES1970$V700002, width=4, pad='0') %>%
  paste0('1970', .) %>%
  as.integer()

ANES1970$age   <- Recode(ANES1970$V700398, '0=NA') %>% as.integer()
ANES1970$bornInUS <- Recode(
  var     = ANES1970$V700363, 
  recodes = '101:199 = TRUE; c(998, 999, 000) = NA; else = FALSE') == 1
ANES1970$educ <- Recode(
  var     = ANES1970$V700269,
  recodes = '11 = 1; 12=2; 13=3; 14=4; 15=5; 16=6; 17:18=7; 21:22=8; c(31,41)=9; c(32,42)=10; c(33,43)=11; c(51,61)=12; 71=13; 81=16; 82:86=17; else=NA') %>%
  as.integer()
ANES1970$yearsTo13 <- pmin(ANES1970$educ, 13)

ANES1970$female <- ANES1970$V700390 == 2
ANES1970$govt.health.7pt <- Recode(ANES1970$V700134, 'c(8,9,0)=NA')
ANES1970$race   <- Recode(
  var       = ANES1970$V700391, 
  recodes   = '1 = "white"; 2 = "black"; else="otherRace"', 
  as.factor = TRUE) %>%
  relevel(., 'white') # make "white" the reference category
ANES1970$state.contemp <- NES_StateRecode(ANES1970$V700018, twoDigit = TRUE) %>% as.character()
ANES1970$stateYoung    <- NES_StateRecode(ANES1970$V700379) 
ANES1970$yearInt       <- 1970
ANES1970$yearInt.fac   <- factor(ANES1970$yearInt) 
ANES1970$yearYoung     <- ANES1970$yearInt - ANES1970$age + 14  



##############################################################################
# SEGREGATION-RELATED MEASURES
##############################################################################
# Lochner and Moretti (2004) use measures like these.  To get the maximum 
# number of cases, they need to be created after the state-of-residence-when-
# young augmentation above.  
ANES1970$blackPostBrown <- 
  ANES1970$race       == 'black' & 
  ANES1970$yearYoung  >= 1958    & 
  ANES1970$stateYoung %IN% c(
    'AL', 'AR', 'DE', 'DC', 'FL', 'GA', 'KY', 'LA', 'MD', 'MS', 'NC', 'OK', 
    'SC', 'TN', 'TX', 'VA', 'WV')
ANES1970$MSDuringRepeal <- 
  ANES1970$race       ==   'white'   &
  ANES1970$yearYoung  %IN% 1957:1982 & 
  ANES1970$stateYoung ==   'MS' 
ANES1970$SCDuringRepeal <- 
  ANES1970$race       ==  'white'   &
  ANES1970$yearYoung %IN% 1956:1971 & 
  ANES1970$stateYoung ==  'SC'
ANES1970$duringRepeal   <- 
  (ANES1970$MSDuringRepeal | ANES1970$SCDuringRepeal) & 
  ANES1970$race == 'white' 
